package com.io.example.demoparent.controller;

import com.io.example.demoparent.bo.User;
import com.io.example.demoparent.service.netty.PushService;
import com.io.example.demoparent.vo.ResultData;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/nettySend")
public class NettSendController {


    @Resource
    private PushService pushService;


    /**
     * 发送消息接口
     *
     * @param id      用户id
     * @param message 发送的消息
     * @return
     */
    @GetMapping("/sendMessage")
    public String sendMessage(String id, String message) {
        if (StringUtils.isEmpty(id)) {
            pushService.pushMsgToAll(message);
        } else {
            pushService.pushMsgToOne(id, message);
        }
        return "true";
    }

    /**
     * 校验测试
     *
     * @param user
     * @Description TODO
     * @Valid 表示对这个对象校验
     * @Date Create by 2022-06-12 14:58
     */
    @PostMapping("addDo")
    public ResultData add(@Valid @RequestBody User user) {
        System.out.println("user = " + user);
        return ResultData.success();
    }

}
